using System;
using System.Threading.Tasks;
using Gj.Galaxy.Logic;
using Unity.Services.Core;
using UnityEngine;

namespace Gj.LeanCloud
{
    public class LeanCloud
    {

        public static LeanCloud Instance;
        public static LeanCloudSettings settings;

        static LeanCloud()
        {
            settings = LoadSettings();
            Instance = new LeanCloud();
        }

        private static LeanCloudSettings LoadSettings()
        {
            var loadedSettings = (LeanCloudSettings)Resources.Load("LeanCloudSettings", typeof(LeanCloudSettings));
            if (loadedSettings == null)
            {
                loadedSettings = ScriptableObject.CreateInstance<LeanCloudSettings>();
                LogTools.Error("LeanCloudSettings is not exist (Resources)");
            }

            return loadedSettings;
        }

        public static async Task Init()
        {

        }

        public static async Task Login(GamePlayer player)
        {
            try
            {
                await Auth.Login(player);
            }
            catch (Exception e)
            {
                LogTools.Error(e.ToString());
            }
        }
    }
}